From: Philip Chimento Date: Wed, 3 Jan 2024 00:29:08 +0000 (-0800) Subject: extensionSystem: Improve error formatting X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~281^2~2^2~181 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=71befc5ff75beede35d1f1101030cb088cfdfd6a;p=gnome-shell.git extensionSystem: Improve error formatting This exposes the formatted error with stack trace and proper location of SyntaxErrors over the bus, instead of just the message. Part-of: --- diff --git a/js/misc/errorUtils.js b/js/misc/errorUtils.js index c2bc1c794..369a06b02 100644 --- a/js/misc/errorUtils.js +++ b/js/misc/errorUtils.js @@ -14,8 +14,8 @@ function formatExceptionStack(error) { return `\n\nStack trace:\n${indentedStack}`; } -function formatExceptionWithCause(error, seenCauses) { - let fmt = formatExceptionStack(error); +function formatExceptionWithCause(error, seenCauses, showStack) { + let fmt = showStack ? formatExceptionStack(error) : ''; const {cause} = error; if (!cause) @@ -39,9 +39,12 @@ function formatExceptionWithCause(error, seenCauses) { * location where a SyntaxError was thrown into account. * * @param {Error} error The error to format + * @param {object} options Formatting options + * @param {boolean} options.showStack Whether to show the stack trace (default + * true) * @returns {string} The formatted string */ -export function formatError(error) { +export function formatError(error, {showStack = true} = {}) { try { let fmt = `${error}`; if (error === null || typeof error !== 'object') @@ -49,12 +52,13 @@ export function formatError(error) { if (error instanceof SyntaxError) { fmt += formatSyntaxErrorLocation(error); - fmt += formatExceptionStack(error); + if (showStack) + fmt += formatExceptionStack(error); return fmt; } const seenCauses = new Set([error]); - fmt += formatExceptionWithCause(error, seenCauses); + fmt += formatExceptionWithCause(error, seenCauses, showStack); return fmt; } catch (e) { return `(could not display error: ${e})`; diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index 0ff282809..ddadb384e 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -9,6 +9,7 @@ import * as Signals from '../misc/signals.js'; import * as Config from '../misc/config.js'; import * as ExtensionDownloader from './extensionDownloader.js'; +import {formatError} from '../misc/errorUtils.js'; import {ExtensionState, ExtensionType} from '../misc/extensionUtils.js'; import * as FileUtils from '../misc/fileUtils.js'; import * as Main from './main.js'; @@ -359,8 +360,7 @@ export class ExtensionManager extends Signals.EventEmitter { if (!extension) return; - const message = error instanceof Error - ? error.message : error.toString(); + const message = formatError(error, {showStack: false}); console.debug(`Changing state of extension ${uuid} to ERROR`); extension.error = message;